// TOWN SCRIPT
//    Town 0: Crystal Caves

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short time = 0;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.

if(get_flag(0,1) == 0) {
	reset_dialog();
	add_dialog_str(0,"As you enter this cavern, your breath catches in your throat. It is stunningly beautiful. Crystal formations line the floor and ceiling, emitting a soft blue light. The walls glow a dull pulsating blue, and everything you see glitters brilliantly.",0);
	add_dialog_str(1,"As well as this, large mushrooms dot the cavern floor, somehow altered and enhanced by the magical properties of the cave. Looking around, you see the prints of heavy boots in the dust - the Empire forces here must already have explored the area.",0);
	add_dialog_str(2,"The whole cavern must be amazingly valuable to the work here on the island - even from the entrance you can feel the high concentration of magical energy in the air. It is probably from here that the crystals used in the portal experiments originate.",0);
	add_dialog_str(3,"However, highly concentrated magic such as the stuff the crystal formations are spewing out can be very dangerous, which might go towards explaining the lack of any major human presence, excluding you of course.",0);
	run_dialog(1);
	set_flag(0,1,1);
}

set_name(6,"Stephens");
set_level(6,5);

set_terrain(22,46,0); //Kill the braziers
set_terrain(26,46,0); //Kill the braziers

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.

while(time < 100) {
		time = time + 1;
	}
if(time == 50)  {
	print_str_color("You faintly hear someone whisper 'Help me'.",2);
	time = 0;
	}

break;

beginstate 10; //Broken Bridge
	message_dialog("The bridge here has been smashed in half by a falling piece of rock, rendering it completely uncrossable.","");
break;

beginstate 11; //North Cavern
	message_dialog("The cave continues to stretch further underground here, heading roughly towards the north. However, a series of cavequakes and rock falls have left the galley impassable.","");
break;

beginstate 12; //East Cavern
	message_dialog("The cave continues to stretch further underground here, heading roughly towards the east. However, a series of cavequakes and rock falls have left the galley impassable.","");
break;

beginstate 13; //Pit
	if(get_flag(0,2) != 1) {
		message_dialog("There is a huge pit worn into the floor here. Peering over the side gives you no indication to the depth of it, and shining your light over it doesn't help either, so you find a small rock and throw it down.","You wait, and wait and wait. And wait. Eventually, after a few moments without hearing anything, you creep slowly away from the edge.");
		set_flag(0,2,1);
	}
break;

beginstate 14; //Bridge
	if(get_flag(0,3) == 0) {
		message_dialog("You ease yourself slowly onto this worn stone bridge. It is a miracle that it is still standing - it must be centuries old. That must mean it was created by the natives of the island; a surprising discovery considering they were supposed to be savages.","It is clear that there was far more to those people than you first thought. Maybe you can learn more about them further inside.");
		set_flag(0,3,1);
	}
break;

beginstate 15; //Locked Door
	if(get_flag(0,4) == 0) {
		message_dialog("The cave here comes to a dead end. A solid stone wall has been built across the gallery. Judging from the architecture, and its general appearance, it must have been here for centuries.","A large stone door stands in the middle of the wall, stretching up over 10 feet. You search every nook and cranny, but don't find any way to open it. Pushing it yields no results either. Whatever lies behind it, you're not going to find out soon.");
		set_flag(0,4,1);
	}
break;	

beginstate 16; //Snake Swamp
	if(get_flag(0,5) == 0) {
		message_dialog("The cave here descends into a swampy mess. Large puddles of murky water line the floor. Some water must have leaked from above and created a reeking grotto of fungi and mould.","As if that wasn't enough, several snakes have adopted the area as their home. If you turn back now, they probably won't attack you, but if you continue any further they look ready to defend their home.");
		set_flag(0,5,1);
	}
break;

beginstate 17;
if(get_flag(0,7) == 0) {
	place_monster(7,35,62,0);
	place_monster(7,38,62,0);
	place_monster(9,39,62,0);
	place_monster(9,37,62,0);
	place_monster(9,36,62,0);
	place_monster(11,38,62,0);
	place_monster(11,37,62,0);
	set_flag(0,7,1);
}
break;

beginstate 18; //Shade animation 
	 if(get_flag(0,6) == 0) {
		 message_dialog("Something ahead catches your eye - there is something coming out of the wall just in front of you...","You pause, terrified, and watch the apparition...");
		force_view_center(38,18);
		activate_hidden_group(1);
		force_instant_terrain_redraw();
		text_bubble_on_char(11,"Help me!");
		force_instant_terrain_redraw();
		pause(5);
		relocate_character(11,39,18);
		force_instant_terrain_redraw();
		pause(5);
		relocate_character(11,38,18);
		force_instant_terrain_redraw();
		pause(8);
		relocate_character(11,37,18);
		force_instant_terrain_redraw();
		pause(8);
		erase_text_bubbles();
		erase_char(11);
		force_instant_terrain_redraw();
		message_dialog("The shade passes through the wall opposite to where it emerged. The wailing voice that cried when you saw it has gone. You wonder what it was...","");
		set_flag(0,6,1);
			}
break;
			 